<!--{json width:"940",title:"发表新帖"}-->
<style type="text/css">
.post_thread_form dt {width: 5%;}
.post_thread_form dd {width: 93%;}
.rich_media_inner
{
	font-size: 15px;
	word-wrap: break-word;
	-webkit-hyphens: auto;
	-ms-hyphens: auto;
	hyphens: auto
}
</style>



<form action="?post-thread-fid-$fid-ajax-1.htm" method="post" id="post_thread_form_$pid" class="post_thread_form" target="_blank">
	<input type="hidden" name="FORM_HASH" value="{FORM_HASH}" />
	<!--{hook common_form_hash_after.htm}-->
	<dl>
		<!--{hook post_thread_subject_before.htm}-->
		<dt><label for="subject">标题：</label></dt>
		<dd style="white-space: nowrap">
			<!--{if $forumselect}-->$forumselect<!--{/if}-->
			<span id="typeselect">
		<!--{if $typeselect1 || $typeselect2 || $typeselect3 || $typeselect4}-->
			<!--{loop $forum[types] $cateid $types}-->
				<!--{if $cateid == 1 && $typeselect1}-->$typeselect1<!--{/if}-->
				<!--{if $cateid == 2 && $typeselect2}-->$typeselect2<!--{/if}-->
				<!--{if $cateid == 3 && $typeselect3}-->$typeselect3<!--{/if}-->
				<!--{if $cateid == 4 && $typeselect4}-->$typeselect4<!--{/if}-->
			<!--{/loop}-->
		<!--{/if}-->
			</span>
			<input type="text" name="subject" id="subject_$pid" value="$thread[subject]" style="width: 500px;" tabindex="100" /> <span class="small grey">(200字)</span>
		</dd>
		<!--{hook post_thread_subject_after.htm}-->
		
		<dt><label for="coverimg">封面：</label></dt>
		<dd>
		<div class="bg1 border shadow">
			<div style="width: 400px; padding: 8px;">
				<div>
					<div  id="uploadInf" ></div>
					<div id="preview"></div>
					<input type="file"  name="Filedata" id="coverimg" multiple />
					<input type="text" name="coverimg" id="valcoverimg" hidden />
					<div class="notice" id="notice" style="display: none;"></div>
				</div>
			</div>
		</div>
		</dd>
		
		
		<dt><label for="thread_message_$pid">内容：</label></dt>
		<dd style="position: relative;"><textarea name="message" id="thread_message_$pid" style="width: 855px; height: 400px;" tabindex="101"></textarea></dd>
		
		<!--{hook post_thread_message_after.htm}-->
		<dt><label for="thread_tags_$pid">标签：</label></dt>
		<dd>
			<input type="text" id="tags_$pid" name="tags" style="width: 500px;" onkeyup="ReplaceDot(this)" /><span class="small grey">(逗号分隔)</span>
		</dd>
		<dt><label for="source">来源：</label></dt>
		<dd>$input[source]</dd>
		<!--<dt ><label for="publishtime">时间：</label></dt>
		<dd style="white-space: nowrap;width: 90%;">
			<input type="text" name="publishtime" id="subject_publictime_$pid" value="$thread[publishtime]" style="width: 100px;" > 
			<img src="view/image/datetimepicker/images/cal.gif" onclick="javascript:NewCssCal('subject_publictime_$pid','yyyyMMdd','dropdown',true,'24')" style="cursor:pointer"/>
			<span class="small grey">（设置文章发布时间）</span>
		</dd>-->
		<dt></dt>
		<dd>
			<input type="submit" class="button bigblue" id="post_thread_submit_$pid" value="完成编辑" tabindex="102" />
			<input type="button" class="button biggrey" value="取消" id="post_thread_cancel_$pid"  tabindex="103" />
			<input type="button" class="button bigblue" value="预览" id="post_thread_preview_$pid"  tabindex="104" />
			
			<!--{hook post_thread_button_end.htm}-->
		</dd>
		
	</dl>
</form>

<div class="dialog border shadow" title="预览" id="dialog1" style="background-color:#fff;display: none;"></div>

<!--{hook post_thread_ajax_js_before.htm}-->

<script type="text/javascript">

function delay_execute(dialog, recall) {
	
	// hook post_thread_delay_execute_start.htm
	
	$('#subject_$pid').focus();
	
	// 自动伸缩，自动提交
	$('#thread_message_$pid').keyup(function(e) {
		if((e.ctrlKey && (e.which == 13 || e.which == 10)) || (e.altKey && e.which == 83)) {
			$('#post_thread_submit_$pid').trigger('click');
			return false;
		}
	});

	$('#post_thread_submit_$pid').click(function() {
	
		$('div.alert').remove();
		$('#post_thread_submit_$pid').disable();
		var postdata = $("#post_thread_form_$pid").serialize();
		$.post($('#post_thread_form_$pid').attr('action'), postdata,  function(s){
			$('#post_thread_submit_$pid').enable();
			var json = json_decode(s);
			if(error = json_error(json)) {alert(error); return false;}
			if(json.status <=0) {
				alert(json.message);
				return false;
			}
			
			json = json.message;
			if(json.subject) {
				$('#subject_$pid').alert(json.subject, {width: 250, delay: 3000}).focus();
				return false;
			}
			if(json.message) {
				$('#thread_message_$pid').parent().alert(json.message, {width: 250, delay: 3000});
				$('#thread_message_$pid')[0].focus();
				return false;
			}
			
			// hook post_thread_submit_after_js.htm
			
			var thread = json.thread;
			
			$('#thread_message_$pid').val('');
	 		
	 		dialog.set_body('<div class="ok">发表成功，页面将自动跳转到列表页！</div>');
	 		setTimeout(function() {
	 			if(thread && (thread.typeid1 || thread.typeid2 || thread.typeid3 || thread.typeid4)) {
	 				var typeidurl = '-typeid1-'+thread.typeid1+'-typeid2-'+thread.typeid2+'-typeid3-'+thread.typeid3+'-typeid4-'+thread.typeid4; 
	 			} else {
	 				var typeidurl = '';
	 			}
	 			window.location= '?thread-index-fid-'+thread.fid+'-tid-'+thread.tid+typeidurl+'.htm';
	 			dialog.close();
	 		}, 500);
		  });
		  
		  // hook post_thread_ajax_post_after.htm
		  
		  return false;
	});
	$('#post_thread_cancel_$pid').click(function() {
		dialog.close();
	});

	$('#post_thread_preview_$pid').click(function() {
		var coverimg = $("#valcoverimg").val();
		var body = '<link rel="stylesheet" type="text/css" href="view/preview.css">'+'<input type="button" class="button bigblue" value="4"   onclick="changepreview(480,320)" /><input type="button" class="button bigblue" value="5" onclick="changepreview(566,320);" /><input type="button" class="button bigblue" value="6"  onclick="changepreview(667,375);" /><input type="button" class="button bigblue" value="plus"  onclick="changepreview(960,540);" /><div class="rich_media_inner"><div id="page-content"><div id="img-content"class="rich_media_area_primary"><p style="text-align:center"><img src="$conf[image_url]'+coverimg+'" alt="" width="100%" \/></p>'
		+'<h2 class="rich_media_title">'+$("#subject_$pid").val()+'</h2>'+'<div class="rich_media_meta_list"><span class="rich_media_meta rich_media_meta_text">萌球宠物'+$("input[name='source']:checked")[0].nextSibling.nodeValue+'</span><span class="rich_media_meta rich_media_meta_text">$_user[username]</span><span class="rich_media_meta_text rich_media_meta_date">{php echo date("m-d H:i",$_SERVER[time])}</span></div></div></div></div><div class="rich_media_content">'+$("#thread_message_$pid").val()+'</div>';
		$('#dialog1').dialog(
			{
				width: 320,
				height: auto,
				modal: false,
				open: true,
				closedestory: false,
				drag: true,
				position: 'left',
				fullicon: false,
				fullscreen: false,
				timeout: 0,
				showtitle: true,
				title: '',
				body: body,
				zIndex: 100
			}
		);
	});

	// 选择版块，AJAX 加载主题分类
	$('#fid').change(function() {
		var fid = this.value;
		$.get('?post-typeselect-fid-'+fid+'-ajax-1.htm', function(s) {
			var json = json_decode(s);
			if(error = json_error(json)) {alert(error); return false;}
			if(json.status <=0) {
				alert(json.message);
				return false;
			}
			
			json = json.message;
			var typeslects = json.typeselect1 + json.typeselect2 + json.typeselect3 + json.typeselect4;
			$('#typeselect').html(typeslects);
		});
	});
	
	// hook post_thread_delay_execute_end.htm
	
	// hook common_form_hash_after_js.htm
}

	function changepreview(height,width){
	
			$('#dialog1').dialog({width:width,height:height+83});
	
	}
</script>

<!--上传缩略图js-->
<script type="text/javascript" src="view/js/zxxFile.js"></script>
<script type="text/javascript" >
//图片上传
var params = {
	fileInput: $("#coverimg").get(0),
	dragDrop: $("#fileDragArea").get(0),
	upButton: $("#coverimg").get(0),
	url: '?attach-uploadimage.htm',
	filter: function(files) {
		var arrFiles = [];
		for (var i = 0, file; file = files[i]; i++) {
			if (file.type.indexOf("image") == 0) {
				if (file.size >= 5120000) {
					alert('您这张"'+ file.name +'"图片大小过大，应小于500k');	
				} else {
					arrFiles.push(file);	
				}			
			} else {
				alert('文件"' + file.name + '"不是图片。');	
			}
		}
		return arrFiles;
	},
	onSelect: function(files) {
		var html = '', i = 0;
		$("#preview").html('<div class="upload_loading"></div>');
		var funAppendImage = function() {
			file = files[i];
			if (file) {
				var reader = new FileReader()
				reader.onload = function(e) {
					html = html + '<div id="uploadList_'+ i +'" class="upload_append_list">'+ 
						'<span id="uploadProgress_' + i + '" class="upload_progress"></span>' +
					'</div>';
					
					i++;
					funAppendImage();
				}
				reader.readAsDataURL(file);
			} else {
				$("#preview").html(html);
				if (html) {
					//删除方法
					$(".upload_delete").click(function() {
						ZXXFILE.funDeleteFile(files[parseInt($(this).attr("data-index"))]);
						return false;	
					});
					//提交按钮显示
					$("#fileSubmit").show();	
				} else {
					//提交按钮隐藏
					$("#fileSubmit").hide();	
				}
			}
		};
		funAppendImage();		
	},
	onDelete: function(file) {
		$("#uploadList_" + file.index).fadeOut();
	},
	onDragOver: function() {
		$(this).addClass("upload_drag_hover");
	},
	onDragLeave: function() {
		$(this).removeClass("upload_drag_hover");
	},
	onProgress: function(file, loaded, total) {
		var eleProgress = $("#uploadProgress_" + file.index), percent = (loaded / total * 100).toFixed(2) + '%';
		eleProgress.show().html(percent);
	},
	onSuccess: function(file, response) {
		$("#valcoverimg").val(response);
		$("#uploadInf").html('<img src="$conf[image_url]' + response +'" height="300" />');
	},
	onFailure: function(file) {
		$("#uploadInf").html("<p>图片" + file.name + "上传失败！</p>");	
		$("#uploadImage_" + file.index).css("opacity", 0.2);
	},
	onComplete: function() {
		//提交按钮隐藏
		$("#fileSubmit").hide();
		//file控件value置空
		$("#fileImage").val("");
	}
};
ZXXFILE = $.extend(ZXXFILE, params);
ZXXFILE.init();
</script>

<!--中文逗号替换为英文-->
<script type="text/javascript">
function ReplaceDot(obj)
{
var oldValue=obj.value;
while(oldValue.indexOf("，")!=-1)//寻找每一个中文逗号，并替换
{
obj.value=oldValue.replace("，",",");
oldValue=obj.value;
}
obj.value = oldValue;
}

</script>
<script src="view/js/datetimepicker/datetimepicker_css.js" type="text/javascript"></script>